package com.allen.service;

import com.allen.bean.Comment;
import com.allen.bean.Result;
import com.allen.mapper.CommentMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @Author: allen
 * @Data: 2021.06.18.20:39
 * 业务逻辑层
 **/

@Service
@Transactional(rollbackFor = RuntimeException.class)
public class CommentService {

    @Autowired
    private CommentMapper commentMapper;

    /**
     * 提交评论
     */

    public Result subComment(Comment comment){
        Result result = new Result();       //实例化对象
        result.setSuccess(false);           //给变量赋值
        result.setDetail(null);
        commentMapper.subc(comment);
        System.out.print(comment.getC_font());
        result.setMsg("上传成功");
        result.setSuccess(true);
        result.setDetail(comment);

        return result;
    }

    /**
     * 查询评论
     */
    public Result selComment(Comment comment){
        Result result = new Result();       //实例化对象
        result.setSuccess(false);           //给变量赋值
        result.setDetail(null);
        List<Comment> list=commentMapper.selc(comment);
        if(list.size()==0){
            result.setMsg("没有查询到评论");
            result.setSuccess(false);
            result.setDetail(comment);
        }else{
            result.setMsg("查询成功,存在评论");
            result.setSuccess(true);
            result.setDetail(list);
        }


        return result;
    }


}
